<?php include "checkSessionForAuthen.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Chỉnh Sửa Thông Tin Giới Thiệu</title>
        <?php include("import.php"); ?>
    </head>
    <body>
        <?php
        include("../service/introductionService.php");
        ?>
        <form action="../action/editIntroductionAction.php" enctype="multipart/form-data" method="post" id="form">
            <!--header-->
            <?php include "header.php"; ?>
            <!--end header-->
            <!-- Container -->
            <div id="container">
                <div class="shell">

                    <!--
                    <div class="small-nav">
                            <a href="product.html">Tài Khoản</a>
                            <span>&gt;</span>
                            anv
                    </div>
                    -->

                    <!-- End Small Nav -->
                    <?php
                    $message = "";
                    if (isset($_GET['message'])) {
                        $deleteMessage = $_GET['message'];
                    }
                    if (isset($deleteMessage)) {
                        if ($deleteMessage == 'ok') {
                            $message = 'Thông tin đã được thay đổi thành công!';
                        } else {
                            $message = 'Không thể thay đổi thông tin';
                        }
                    }

                    if ($message == '') {
                        $class = 'msg msg-ok msg-hidden';
                    } else {
                        $class = 'msg msg-ok';
                    }
                    ?>	
                    <div class="<?php echo($class); ?>" id="msgOK">
                        <p><strong><?php echo($message); ?></strong></p>
                        <a href="#" onclick="hideMessage()" class="close">close</a>
                    </div>

                    <br />
                    <!-- Main -->
                    <div id="main">
                        <div class="cl">&nbsp;</div>

                        <!-- Content -->
                        <div id="content">        
                            <!-- Box -->
                            <div class="box">
                                <!-- Box Head -->
                                <div class="box-head">
                                    <h2>Chỉnh Sửa Thông Tin Giới Thiệu</h2>
                                </div>
                                <!-- End Box Head -->

                                <?php
								$imagePath = '../img/introduction/';
								$directory = opendir($imagePath);
								$images = array();
								$count = 0;
								
								while (($file = readdir($directory)) !== false) {
									if ($file != "." && $file != "..") {
										$count++;
										$images[substr($file, 0, 1)] = $file;
									}
								}
								
                                if (isset($_GET["id"])) {
                                    $result = getIntroductionById($_GET["id"]);
                                    while ($row = ConnectionManager::getInstance()->fetchArray()) {
                                        ?>
                                        <!-- Form -->
                                        <div class="form">
                                            <p>
                                                <input type="hidden" name="insid" id="insid" value="<?php echo $row["INT_ID"]; ?>"/>
                                                <textarea id="content" name="content" class="ckeditor"><?php echo $row["INT_CONTENT"]; ?></textarea>
                                            </p>
                                        </div>

                                        <p>
                                            <label>Hình ảnh 1</label>
                                            <input type="file" class="field size1" name="img1"/>
                                           	<?php if($images[1] != '') echo "<img src='".$imagePath.$images[1]."' height=\"220\" width=\"272\" >" ?>
                                        </p>
                                        <p>
                                            <label>Hình ảnh 2</label>
                                            <input type="file" class="field size1" name="img2"/>
                                            <?php if($images[2] != '') echo "<img src='".$imagePath.$images[2]."' height=\"220\" width=\"272\" >" ?>
                                        </p>
                                        <p>
                                            <label>Hình ảnh 3</label>
                                            <input type="file" class="field size1" name="img3"/>
                                            <?php if($images[3] != '') echo "<img src='".$imagePath.$images[3]."' height=\"220\" width=\"272\" >" ?>
                                        </p>
                                         <p>
                                            <label>Hình ảnh 4</label>
                                            <input type="file" class="field size1" name="img4"/>
                                            <?php if($images[4] != '') echo "<img src='".$imagePath.$images[4]."' height=\"220\" width=\"272\" >" ?>
                                        </p>
                                         <p>
                                            <label>Hình ảnh 5</label>
                                            <input type="file" class="field size1" name="img5"/>
                                            <?php if($images[5] != '') echo "<img src='".$imagePath.$images[5]."' height=\"220\" width=\"272\" >" ?>
                                        </p>
                                        <!-- End Form -->
                                        <?php
                                    }
                                }
                                ?>
                                <!-- Form Buttons -->
                                <div class="buttons">
                                    <input type="submit" class="button" value="Chấp nhận" name="updateIns"/>
                                    <input type="button" class="button" value="Trở Về" onclick="window.location='introduction.php'" />
                                </div>
                                <!-- End Form Buttons -->

                            </div>
                            <!-- End Box -->

                        </div>
                        <!-- End Content -->	
                        <div class="cl">&nbsp;</div>			
                    </div>
                    <!-- Main -->
                </div>
            </div>
            <!-- End Container -->
            <!--footer-->
            <?php include "footer.php"; ?>
            <!--end footer-->
            <?php ConnectionManager::getInstance()->closeConnection(); ?>
        </form>
    </body>
</html>
